package crime;

import repast.simphony.engine.schedule.ScheduledMethod;
import repast.simphony.space.continuous.ContinuousSpace;
import repast.simphony.space.grid.Grid;
import repast.simphony.space.grid.GridPoint;

public class Criminal {

	private final int MONEYINWALLET = 100; 
	private ContinuousSpace<Object> space;
	private Grid<Object> grid;
	
	private int wealth;
	private boolean stop = false;

	public Criminal(ContinuousSpace<Object> space, Grid<Object> grid) {
		this.space = space;
		this.grid = grid;
		wealth = MONEYINWALLET;
	}
	
	@ScheduledMethod(start = 1, interval = 1)
	public void step() {
		// get the grid location of this
		GridPoint pt = grid.getLocation(this);
		int curx=pt.getX();
		int cury=pt.getY();
		//stop if reaches the farthest
		int diffx=curx-50;
		int diffy=cury-50;
		if(!stop&&wealth==10){//(Math.abs(diffx)+Math.abs(diffy))){
			stop=true;
			System.out.println(Math.sqrt(diffx*diffx+diffy*diffy));
		}
		if(stop)
			return;
		int dir = (int)(System.currentTimeMillis()%4);
		if (dir==0) curx++;
		else if (dir==1) curx--;
		else if (dir==2) cury++;
		else cury--;
		grid.moveTo(this, curx, cury);
		wealth--;
	}
}
